import React from 'react';

class DigitalClock extends React.Component {
  constructor(props) {
    super(props);
    this.state={
      date: new Date()
    };
  }

  componentDidMount() {
    this.timer=setInterval(() => {
      this.setState({
        date: new Date()
      });
    }, 1000);
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }

  render() {
    return (
      <div className="bg-light w-auto border rounded-3 my-2 p-3">
        <p className="text-center fs-3 align-middle m-0">{this.state.date.toLocaleTimeString()}</p>
      </div>
    );
  }
}

export default DigitalClock;
